package com.zkingsoft.actions.admin;

import java.util.Arrays;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.zkingsoft.actions.common.BaseController;
import com.zkingsoft.model.InterfaceCate;
import com.zkingsoft.plugin.pojo.PaginationVO;
import com.zkingsoft.plugin.util.WebUtil;
import com.zkingsoft.pojo.AjaxResult;
import com.zkingsoft.services.InterfaceCateService;

/**
 * This field was generated by Zking.software.Codegen.
 * 
 * @date 2016-09-09 15:09
 */
@Controller
@RequestMapping(value = "admin/interfaceCate")
public class InterfaceCateController extends BaseController {

	@Resource
	private InterfaceCateService currentService;

	/**
	 * 子菜单入口
	 */
	@RequestMapping(value = "/enter")
	public String enter(Long projId,String projName) {
		WebUtil.getRequest().setAttribute("projId", projId);
		return "/admin/interfaceCate-list";
	}
	
	/**
	 * 列表显示
	 */
	@RequestMapping(value = "/showList")
	public @ResponseBody AjaxResult showList(InterfaceCate interfaceCate, PaginationVO pageVo) {
		return showList(currentService, interfaceCate, pageVo);
	}

	/**
	 * 查询项目中所有的分类
	 */
	@RequestMapping(value = "/all")
	public @ResponseBody AjaxResult showList(InterfaceCate interfaceCate) {
		if (interfaceCate.getProjId() != null) {
			return new AjaxResult(AjaxResult.STATUS_OK, null, null, currentService.findByModel(interfaceCate), 0);
		}
		return new AjaxResult(AjaxResult.STATUS_OK, "项目id为null", null, null, 0);
	}

	/**
	 * 新增或者修改页面
	 */
	@RequestMapping(value = "/addOrModify")
	public @ResponseBody AjaxResult addOrModify(InterfaceCate interfaceCate) {
		if (interfaceCate.getId() != null) {
			return modify(currentService, interfaceCate, "接口类型");
		} else {
			return add(currentService, interfaceCate, "接口类型");
		}
	}

	/**
	 * 进入修改界面
	 */
	@RequestMapping(value = "/editForm")
	public String editForm(Long id,Long projId) {
		WebUtil.getRequest().setAttribute("projId", projId);
		if (id != null) {
			InterfaceCate interfaceCate = currentService.findById(id);
			WebUtil.getRequest().setAttribute("obj", interfaceCate);
		}
		return "admin/interfaceCate-form";
	}

	/**
	 * 进入列表页面
	 */
	@RequestMapping(value = "/goList")
	public String goList(Long id) {
		WebUtil.getSession().setAttribute("projId", id);
		return "admin/interfaceCate-list";
	}

	/**
	 * 删除
	 */
	@RequestMapping(value = "/del")
	public @ResponseBody AjaxResult del(String keys) {
		return remove(currentService, keys);
	}

	@RequestMapping(value = "/findById")
	public @ResponseBody AjaxResult findById(Long id) {
		InterfaceCate interfaceCate = super.findById(currentService, id);
		return new AjaxResult(AjaxResult.STATUS_OK, null, null, Arrays.asList(interfaceCate), 0);
	}

}